<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of ImportFieldMappingController
 *
 * @author menglei
 */
class ImportFieldMappingController extends PsController
{
	public function accessRules()
	{
		return CMap::mergeArray(array(
					array('allow',
						'users' => array('@'),
					)), parent::accessRules());
	}
	
	public function filters()
	{
		return CMap::mergeArray(parent::filters(), array(
					'ajaxOnly 
						+ getSavedMapping'
				));
	}
	
	public function actionGetSavedMapping()
	{
		$response = array();
		
		$id = $_POST['id'];
		
		if(!empty($id)) {
			$model = ImportFieldMapping::model()->findByPk($id);
			
			$response['data'] = $model->attributes;
			$response['result'] = 'success';
		} else {
			$response['result'] = 'failed';
		}
		
		print(json_encode($response));
	}
	
	public function actionDeleteSavedMapping()
	{
		$response = array();
		
		$id = $_POST['id'];
		
		if(!empty($id)) {
			$cnt = ImportFieldMapping::model()->deleteByPk($id);
			$response['data'] = $id;
			$response['result'] = 'success';
		} else {
			$response['result'] = 'failed';
		}
		
		print(json_encode($response));
	}
}

?>
